#include <stdio.h>

#define N 6

void merge(int *arr, int left, int mid, int right)
{
    static int tmp[N];
    int i = left, j = mid + 1, k = 0;
    while (i <= mid && j <= right)
    {
        if (arr[i] > arr[j])
        {
            tmp[k++] = arr[i++];
        }
        else
        {
            tmp[k++] = arr[j++];
        }
    }
    while (i <= mid)
    {
        tmp[k++] = arr[i++];
    }
    while (j <= right)
    {
        tmp[k++] = arr[j++];
    }
    for (int i = 0; i < k; i++)
    {
        arr[left + i] = tmp[i];
    }
}

void merge_sort(int *arr, int left, int right)
{
    if (left >= right)
    {
        return;
    }
    int mid = left + (right - left) / 2;
    merge_sort(arr, left, mid);
    merge_sort(arr, mid + 1, right);
    merge(arr, left, mid, right);
}

int main()
{
    int arr[N] = {3, 1, 5, 6, 2, 0};
    merge_sort(arr, 0, N - 1);
    for (int i = 0; i < N; i++)
    {
        printf("%d\n", arr[i]);
    }

    return 0;
}